package com.gujiangbo.chapter02;

/**
 * @Author: gujiangbo.co
 * @Contact: 646832012@qq.com
 * @Date: 2022/3/21 15:08
 * @Version: 1.0
 * @Description:
 */
public class JavaClassLoader {

    public static void main(String[] args) throws ClassNotFoundException {
        JavaClassLoader javaClassLoader = new JavaClassLoader();
        ClassLoader appClassLoader = javaClassLoader.getClass().getClassLoader();
        //sun.misc.Launcher$AppClassLoader@18b4aac2
        System.out.println(appClassLoader);
        ClassLoader extClassPoader = appClassLoader.getParent();
        ///sun.misc.Launcher$ExtClassLoader@61bbe9ba
        System.out.println(extClassPoader);
        ClassLoader bootstarpClassLoader = extClassPoader.getParent();
        System.out.println(bootstarpClassLoader);
        // 获取ClassLoader 方式
        // 方式1
        ClassLoader stringClassLoader = Class.forName("java.lang.String").getClassLoader();
        System.out.println(stringClassLoader);
        // 方式2 获取线程上下文的CLassLoader
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        System.out.println(contextClassLoader);
        // 方式3 获取系统类加载器ClassLoader
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        ClassLoader extClassLoader = systemClassLoader.getParent();
        System.out.println(extClassLoader);
        System.out.println(systemClassLoader);


    }
}
